import {Component} from 'react'
import propTypes from 'prop-types';
import {login} from '../api/auth'
import {getList} from '../api/account'
class UserLogin extends Component{
    constructor(props){

        super();
        this.state={
           list:[]
        }

      
    }
    async getData(){


     const res=await getList({});
     if(res.code==10000){
          this.setState({list:res.data.list})
     }

     console.log(11111111111,res);

    }
    login=()=>{

       let data={username:this.username.value,pwd:this.pwd.value};

       login(data).then(res=>{
        console.log(111111111,res);

        sessionStorage.setItem("token",res.data.token)

        this.getData();


       })

       console.log(data);
 
    }
    render(){
        return(
            <div>

               <div>
                    列表
                    <table>
                         <tbody>
                          <tr>
                              <td>姓名</td><td>电话</td>
                          </tr>
                          {
                              this.state.list.map((item,index)=>(

                                   <tr key={item.id}>
                                   <td>{item.name}</td><td>{item.mobile}</td>
                                    </tr>
                              ))
                          }
                          </tbody>
                       
                    </table>
               </div>

          
                <div>
                    账号:<input ref={ref1=>this.username=ref1}></input>
                </div>
                <div>
                    密码:<input ref={ref1=>this.pwd=ref1}></input>
                </div>
                <button onClick={this.login}>登录</button>
            </div>
        )
    }
}
export default UserLogin;